/*
* StepService.java
* Created on  202015/5/1 13:30
* 版本       修改时间          作者      修改内容
* V1.0.1    202015/5/1       panzhuowen    初始版本
*
*/

package com.infitecs.eyas.step.service;

import com.infitecs.eyas.boiler.dao.AirGasParameterDao;
import com.infitecs.eyas.boiler.dao.EfficiencyDao;
import com.infitecs.eyas.boiler.dao.SodaParameterDao;
import com.infitecs.eyas.boiler.model.AirGasParameter;
import com.infitecs.eyas.boiler.model.Efficiency;
import com.infitecs.eyas.boiler.model.SodaParameter;
import com.infitecs.eyas.combustion.dao.BurnDao;
import com.infitecs.eyas.combustion.dao.ChimneyDao;
import com.infitecs.eyas.combustion.dao.CleanDao;
import com.infitecs.eyas.combustion.model.CalculateBurn;
import com.infitecs.eyas.combustion.model.CalculateChimney;
import com.infitecs.eyas.combustion.model.CalculateClean;
import com.infitecs.eyas.constant.Constant;
import com.infitecs.eyas.mill.dao.MillSelectDao;
import com.infitecs.eyas.mill.model.MillSelect;
import com.infitecs.eyas.nature.dao.NatureDao;
import com.infitecs.eyas.nature.model.Nature;
import com.infitecs.eyas.power.dao.OperateFieldDao;
import com.infitecs.eyas.power.dao.PowerDao;
import com.infitecs.eyas.power.model.Power;
import com.infitecs.eyas.quality.dao.AshDao;
import com.infitecs.eyas.quality.dao.BurstDao;
import com.infitecs.eyas.quality.dao.ElementDao;
import com.infitecs.eyas.quality.dao.IndustryDao;
import com.infitecs.eyas.quality.model.Ash;
import com.infitecs.eyas.quality.model.Burst;
import com.infitecs.eyas.quality.model.Element;
import com.infitecs.eyas.quality.model.Industry;
import com.infitecs.eyas.runcoalbin.dao.CoalBunkerDao;
import com.infitecs.eyas.runcoalbin.model.CoalBunker;
import com.infitecs.eyas.step.dao.StepDao;
import com.infitecs.eyas.step.modal.StepInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类的描述信息
 *
 * @author panzhuowen
 * @version 1.0.1
 */
@Service
public class StepService {

    @Autowired
    private StepDao stepDao;
    @Autowired
    private ElementDao elementDao;
    @Autowired
    private OperateFieldDao operateFieldDao;
    @Autowired
    private IndustryDao industryDao;
    @Autowired
    private PowerDao powerDao;
    @Autowired
    private AshDao ashDao;
    @Autowired
    private NatureDao natureDao;
    @Autowired
    private BurstDao burstDao;
    @Autowired
    private SodaParameterDao sodaParameterDao;
    @Autowired
    private AirGasParameterDao airGasParameterDao;
    @Autowired
    private EfficiencyDao efficiencyDao;

    @Autowired
    private CoalBunkerDao coalBunkerDao;
    @Autowired
    private MillSelectDao millSelectDao;

    @Autowired
    private BurnDao burnDao;
    @Autowired
    private CleanDao cleanDao;
    @Autowired
    private ChimneyDao chimneyDao;

    public boolean addNewStep(Integer caseId, int step) {
        StepInfo info = getStepInfo(caseId);
        switch (step) {
            case Constant.STEP_ID_1:
                info.setStepId(Constant.STEP_ID_1);
                break;
            case Constant.STEP_ID_2:
                info.setStepId(Constant.STEP_ID_2);
                break;
            case Constant.STEP_ID_3:
                info.setStepId(Constant.STEP_ID_3);
                break;
            case Constant.STEP_ID_4:
                info.setStepId(Constant.STEP_ID_4);
                break;
            case Constant.STEP_ID_5:
                info.setStepId(Constant.STEP_ID_5);
                break;
        }
        return stepDao.addNewStep(info);
    }

    public int findStepIdByCaseId(int caseId) {
        return stepDao.findStepIdByCaseId(caseId);
    }

    public int findStepIdByCaseIdWithNo(int caseId) {
        return stepDao.findStepIdByCaseIdWithNo(caseId);
    }

    public boolean checkIsNotGoBack(int stepId, int caseId) {
        return stepDao.checkIsGoBack(stepId, caseId) == 0;
    }

    private StepInfo getStepInfo(int caseId) {
        StepInfo stepInfo = new StepInfo();
        stepInfo.setCaseId(caseId);
        stepInfo.setState(Constant.STEP_OVER_STATE_0);
        return stepInfo;
    }

    public int getFinishStepId(int caseId, int stepId) {
        return stepDao.getFinishStepId(caseId, stepId);
    }

    public int updateStepStateing(int caseId, int stepId) {
        return stepDao.updateStepStateing(caseId, stepId);
    }

    public int updateStepStateFinish(int caseId, int stepId) {
        return stepDao.updateStepStateFinish(caseId, stepId);
    }


    public int getMzFxStep(int caseId) {
        int step = 0;
        Power powerTitle = powerDao.getCaseById(caseId + "");
        if (powerTitle != null) {
            step += 1;
        }
        Industry industry = industryDao.getIndustryByPowerCaseId(caseId);
        if (industry != null) {
            step += 1;
        }
        Element element = elementDao.getElementByPowerCaseId(caseId);
        if (element != null) {
            step += 1;
        }
        Ash ash = ashDao.getAshByPowerCaseId(caseId);
        if (ash != null) {
            step += 1;
        }
        Burst burst = burstDao.getBurstByPowerCaseId(caseId);
        if (burst != null) {
            step += 1;
        }
        Nature nature = natureDao.getNatureByPowerCaseId(caseId);
        if (nature != null) {
            step += 1;
        }
        return step;
    }

    public int getGlStep(int caseId) {
        int step = 6;
        SodaParameter sodaParameter = sodaParameterDao.getSodaParameter(caseId);
        if (sodaParameter != null) {
            step++;
        }
        AirGasParameter airGasParameter = airGasParameterDao.getAirGasParameter(caseId);
        if (airGasParameter != null) {
            step++;
        }
        Efficiency efficiency = efficiencyDao.getEfficiencyByPowerCaseId(caseId);
        if (efficiency != null) {
            step++;
        }
        return step;
    }

    public int getYmcStep(int caseId) {
        int step = 9;
        CoalBunker coalBunker = coalBunkerDao.getCoalBunker(caseId);
        if (coalBunker != null) {
            step++;
        }
        return step;
    }

    public int geRsStep(int caseId) {
        int step = 10;
        CalculateBurn oldData = burnDao.getCalculateBurnByCaseId(caseId);
        if (oldData != null) {
            step++;
        }

        CalculateClean calculateClean = cleanDao.getCalculateClean(caseId);
        if (calculateClean != null) {
            step++;
        }
        CalculateChimney calculateChimney = chimneyDao.getCalculateChimney(caseId);
        if(calculateChimney!=null){
            step++;
        }

        return step;
    }

    public int geMmjStep(int caseId) {
        int step = 13;
        MillSelect millSelect = millSelectDao.getMillSelect(caseId);
        if (millSelect != null) {
            step++;
        }
        return step;
    }
}
